﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Super.Common.Strings;

namespace Super.Common
{
    public class Number
    {
        /// <summary>
        /// 获得流水号 12位日期+4位随机数
        /// </summary>
        /// <param name="Number">随机数默认4位</param>
        /// <returns></returns>
        /// <remarks>Richwong 11.07.12</remarks>
        public static long GetSerialNumber(int Number = 4)
        {
            var ranName = DateTime.Now.ToString("yyMMddHHmmss");
            ranName += StringPlus.GetRandNum(Number);
            return long.Parse(ranName);
        }

        /// <summary>
        /// 获得需求号，16位数字
        /// </summary>
        /// <param name="Number"></param>
        /// <returns></returns>
        /// <remarks>Richwong 11.07.12</remarks>
        public static long GetTransactionId(int Number = 2)
        {
            string num = DateTime.Now.ToString("ssmmyyMMddff");
            num += StringPlus.GetRandNum(Number);
            return long.Parse(num);
        }

        /// <summary>
        /// 获得UID
        /// </summary>
        /// <param name="id">用户主键</param>
        /// <returns></returns>
        /// <remarks>赵鑫 11.07.18</remarks>
        public static int GetUID(int id)
        {
            object o = new object();
            int uid = 0;
            lock (o)
            {
                uid = 10000 + id;
            }
            return uid;
        }

        /// <summary>
        /// 获得手机验证码
        /// </summary>
        /// <returns></returns>
        /// <remarks>赵鑫 11.09.10</remarks>
        public static string GetMobileCode()
        {
            return StringPlus.GetRandNum(6);
        }

        /// <summary>
        /// 获取随机数
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static int GetRandomNumber(int length = 6)
        {
            return StringPlus.GetRandNum(length).ToInt(0);
        }

        /// <summary>
        /// 获得邮件验证码
        /// </summary>
        /// <returns></returns>
        public static string GetEmailCode()
        {
            string num = StringPlus.GetRandNum(8);
            return num;
        }
    }
}
